home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8230 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: maverick.tad.eds.com!nemesis!venkat
  2. From: venkat@nemesis.pln.rboc.eds.com (User Jdsmith)
  3. Newsgroups: gnu.g++,gnu.g++.help,comp.lang.c++
  4. Subject: Overloaded new operator in C++
  5. Date: 15 Feb 1996 22:23:10 GMT
  6. Organization: Somewhere in EDS...
  7. Message-ID: <4g0boe$c37@maverick.tad.eds.com>
  8. NNTP-Posting-Host: nemesis.pln.rboc.eds.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I am experiencing a problem with overloading the 
  12. new operator when allocating an array of classes.
  13.  
  14. I do the following and my overloaded new operator is
  15. called as expected:
  16.  
  17. ptr = new ClassThatOverloadsNew;
  18.  
  19. But when I do this:
  20.  
  21. ptr = new ClassThatOverloadsNew[5];
  22.  
  23. The default new operator is called.
  24.  
  25. What needs to be done to get an overloaded new operator to be called
  26. when allocating an array of data types?  Does C++ even allow this 
  27. to be done?  I have checked several C++ manuals and none explicitely 
  28. state that this can be done (and none say that it cannot be done!).
  29. I assumed that the overloaded new operator would be called with the
  30. number of bytes (the first parameter) being set to:
  31.  
  32. sizeof(class) * arrayCount
  33.  
  34. But this is not the case.  Does anybody know how to solve this problem?
  35. I'm sure it is supported and is simple to do, I just have not found the
  36. right documentation on how to do it.  My assumptions have been wrong so
  37. far, so I need some help.
  38.  
  39. Thanks in advance,
  40.  
  41. John Smith
  42. Systems Engineer, Electronic Data Systems
  43.